package edu.pku.sei.modeler.uml.commands.usecase;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.structure.MetaLink;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.UseCases.*;
import edu.pku.sei.modeler.uml.commands.ConnectionModelCreateCommand;
import edu.pku.sei.modeler.uml.commands.UMLConnectionCreateCommand;

public class UMLIncludeCreateCommand extends ConnectionModelCreateCommand {


	public UMLIncludeCreateCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel) {
		super(connectionModel, sourceModel);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean canExecute() {
		if (sourceModel instanceof UseCase
				&& targetModel instanceof UseCase) {
			return true;
		}

		return false;
	}

	@Override
	public void execute() {
		UseCase sourceUseCase = (UseCase)sourceModel;
		Include includeElement = (Include)connectionModel;
		includeElement.setContainer(sourceUseCase);
		includeElement.setAddition((UseCase)targetModel);
		includeElement.setModel(sourceUseCase.getModel());
		sourceUseCase.getInclude().add(includeElement);
		

	}

	@Override
	public void undo() {
		UseCase sourceUseCase = (UseCase)sourceModel;
		Include includeElement = (Include)connectionModel;
		sourceUseCase.getInclude().remove(includeElement);
		
	}

}
